package leetcode.code1154;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;
import leetcode.helper.MaxDebug;

public class Solution implements IDebug {

	private static int[] months = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	private static int[] monthSum = new int[13];

	static {
		for (int i = 1; i <= 12; i++) {
			monthSum[i] = monthSum[i - 1] + months[i - 1];
		}
	}

	public int dayOfYear(String date) {
		char[] cc = date.toCharArray();
		int year = this.getNum(cc, 0, 3), month = this.getNum(cc, 5, 6), day = this.getNum(cc, 8, 9);
		int ans = monthSum[month - 1] + day;
		if (month > 2 && (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))) {
			ans += 1;
		}
		return ans;
	}

	private int getNum(char[] cc, int begin, int end) {
		int num = 0;
		while (begin <= end) {
			char c = cc[begin++];
			num = num * 10 + c - '0';
		}
		return num;
	}

	@Override
	public void debug1() {
		HelpDebug.compare(61, this.dayOfYear("2004-03-01"));
	}

	@Override
	public void debug2() {
		HelpDebug.compare(60, this.dayOfYear("2003-03-01"));
	}

	@Override
	public void debug3() {
		HelpDebug.compare(9, this.dayOfYear("2019-01-09"));

	}

	@Override
	public void debug4() {
		HelpDebug.compare(41, this.dayOfYear("2019-02-10"));

	}

	public void debug5() {
		HelpDebug.compare(212, this.dayOfYear("2001-07-31"));

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		MaxDebug.debug14(so);
		so.debug5();
	}

}
